package com.sikaryofficial.information.controller;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.information.domain.dto.datasync.ArticleMQReq;
import com.sikaryofficial.information.domain.dto.datasync.ArticleRecommendMQReq;
import com.sikaryofficial.information.message.body.InformationMessage;
import com.sikaryofficial.information.message.product.ProductProcess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章数据同步
 *
 * @author qinjinyuan
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/dataSync")
@Api(tags = "文章数据同步服务")
public class ArticleDataSyncController extends BaseController {
    @Autowired
    private ProductProcess productProcess;
    /**
     * 消息生产-提供给外部进行数据同步接口
     */
    @PostMapping("/mq/article")
    @ApiOperation("文章数据同步")
    public R<Boolean> articleSync(@Validated @RequestBody ArticleMQReq req) {
        // 生产数据同步消息 topic
        return R.ok(productProcess.sendDelayMessage(InformationMessage.builder()
                .type(req.getType())
                .businessType(req.getBusinessType())
                .articleList(req.getData())
                .build()));
    }
    /**
     * 消息生产-提供给外部进行数据同步接口
     */
    @PostMapping("/mq/articleRecommend")
    @ApiOperation("文章推荐数据同步")
    public R<Boolean> articleRecommendSync(@Validated @RequestBody ArticleRecommendMQReq req) {
        // 文章数据同步消息 topic
        return R.ok(productProcess.sendDelayMessage(InformationMessage.builder()
                .type(req.getType())
                .userId(req.getUserId())
                .businessType(req.getBusinessType())
                .articleRecommendList(req.getData())
                .build()));
    }
}